package cn.nfwx.tv.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import cn.nfwx.tv.R;


/**
 * 回看时间列表适配器
 * Created by zb.liu by  2017/11/2.
 */
public class LookBackDateAdapter extends BaseAdapter {
    private Context mContext;
    private int mSelect = 0;//选中项
    private String[] titles = new String[]{"08/29", "08/30", "昨天", "今天", "09/02", "09/03", "09/04", "09/05"};

    public LookBackDateAdapter(Context mContext) {
        this.mContext = mContext;
    }

    @Override
    public int getCount() {
        return titles.length;
    }

    @Override
    public Object getItem(int position) {
        return titles[position];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.activity_tvprogram_left_item, null);
            holder = new ViewHolder();
            holder.tv_name = (TextView) convertView.findViewById(R.id.tv_title);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.tv_name.setText(titles[position]);

        if (mSelect == position) {
            holder.tv_name.setSelected(true);
            holder.tv_name.setPressed(true);
            holder.tv_name.setBackgroundResource(R.drawable.select_lbdate_bg);  //选中项背景
            holder.tv_name.setTextColor(mContext.getResources().getColor(R.color.black));
        } else {
            holder.tv_name.setSelected(false);
            holder.tv_name.setPressed(false);
            holder.tv_name.setTextColor(mContext.getResources().getColor(R.color.white));
        }
        return convertView;
    }

    public void setSelectItem(int selectItem) {
        this.mSelect = selectItem;
        notifyDataSetChanged();
    }

    static class ViewHolder {
        private TextView tv_name;
    }
}
